<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head><title>Print page</title></head>
<g:javascript library="prototype"/>

<body>
<div>
    <object id="factory" style="display: none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext codebase="smsx.cab#Version=6,3,435,20">
    </object>
</div>
<div id="printContent">
    <g:render template="recipt" model="[jobInstance:jobInstance]"/>
</div>
<script type="text/javascript">

    var strNothingToPrint = "Nothing to Print!";
    window.onload = function() {
        var str = trim($('printContent').innerHTML);

        if (str.length == 0) {
            alert(strNothingToPrint);
            window.close();
        } else if (str.length > 0) {
            if (factory) {
                try {
                    //printBase('', '');
                    factory.printing.Print(false);
                    window.close();
                    return;
                } catch(e) {
                    alert(e.message);
                    window.setTimeout(printAgain, 3000);
                }
                ;
            } else {
                alert("您的浏览器不支持直接打印，\r\n请把IE的安全选项设置为中级！");
                window.print();
                window.close();
            }
        }
    }

    function printAgain() {
        try {
            //alert("重新尝试打印");
            factory.printing.Print(false);
            window.close();
        } catch(e) {
            window.setTimeout(printAgain, 3000);
        }
    }

    function trim(str) {
        var strRet = str.replace(/^\s*/, "");
        strRet = strRet.replace(/\s*$/, "");
        return(strRet);
    }

    function printBase(header, footer) {
        factory.printing.header = header;//页眉
        factory.printing.footer = footer;//页脚
        factory.printing.portrait = true;//true为纵向打印，flase为横向打�?
        factory.printing.leftMargin = 0.5;//左页边距
        factory.printing.topMargin = 0.5;//上页边距
        factory.printing.rightMargin = 0.5;//右页边距
        factory.printing.bottomMargin = 0.5;//下页边距
    }
</script>
</body>
</html>